import http from '@/utils/http'
import type { LabelValueState } from '@/types/global'

const BASE_URL = '/task/info'

export interface InfoResp {
  id: string
  name: string
  mark: string
  projectId: string
  deviceId: string
  planStartTime: string
  planEndTime: string
  actualStartTime: string
  actualEndTime: string
  status: string
  templateId: string
  createUserString: string
  updateUserString: string
  fileTopic: string
  testPlanFile: string
  sensorConfirmFile: string
  sensorInstallFile: string
  trialChangeFile: string
  fieldTestFile: string
}
export interface InfoDetailResp {
  id: string
  name: string
  mark: string
  projectId: string
  deviceId: string
  planStartTime: string
  planEndTime: string
  actualStartTime: string
  actualEndTime: string
  status: string
  templateId: string
  createUser: string
  createTime: string
  updateUser: string
  updateTime: string
  createUserString: string
  updateUserString: string
  fileTopic: string
  testPlanFile: string
  sensorConfirmFile: string
  sensorInstallFile: string
  trialChangeFile: string
  fieldTestFile: string
}
export interface InfoQuery {
  name: string
  planStartTime: string
  planEndTime: string
  actualStartTime: string
  actualEndTime: string
  status: string
  sort: Array<string>
}
export interface InfoPageQuery extends InfoQuery, PageQuery {}

/** @desc 查询测试任务列表 */
export function listInfo(query: InfoPageQuery) {
  return http.get<PageRes<InfoResp[]>>(`${BASE_URL}`, query)
}

/** @desc 查询测试任务详情 */
export function getInfo(id: string) {
  return http.get<InfoDetailResp>(`${BASE_URL}/${id}`)
}

/** @desc 新增测试任务 */
export function addInfo(data: any) {
  return http.post(`${BASE_URL}`, data)
}

/** @desc 修改测试任务 */
export function updateInfo(data: any, id: string) {
  return http.put(`${BASE_URL}/${id}`, data)
}

/** @desc 删除测试任务 */
export function deleteInfo(id: string) {
  return http.del(`${BASE_URL}/${id}`)
}

/** @desc 导出测试任务 */
export function exportInfo(query: InfoQuery) {
  return http.download<any>(`${BASE_URL}/export`, query)
}

/** @desc 查询任务列表 */
export function listTaskDict(query?: { status: number }) {
  return http.get<LabelValueState[]>(`${BASE_URL}/dict`, query)
}
